package com.example.springDemo.controller;

import com.example.springDemo.bean.Car;
import com.example.springDemo.bean.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//@Controller//开启控制器（必须）
//@ResponseBody//表示返回的值直接返回到浏览器

@RestController//==@Controller+@ResponseBody
public class demo {

    @Autowired//自动装配
    Car car;

    @Autowired
    Person person;

    @Value("${person.userName}:里斯")
    private String name;

    @GetMapping("/lisi")
    public String lisi(){
        return "hello" + name;
    }

    @RequestMapping("/person")
    public Person person(){
//        System.out.println(person.getUserName());
        return person;
    }

    @RequestMapping("/car001")
    public Car car(){
        return car;
    }

    @RequestMapping("/hello")
    public String hello(@RequestParam("name")String name){

        return "Hello "+name;
    }
    @Value("${MAVEN_HOME}")//获取环境变量的值
    private String msg;
    public String getMag(){
        return msg;
    }

}
